﻿using System;
using System.Web;

namespace JYH.Framework
{
    /// <summary>
    /// 存 Session对象
    /// </summary>
    public class SessionUser
    {
        /// <summary>
        /// 登录用户主键
        /// </summary>
        public string UserId { get; set; }
        /// <summary>
        /// 编号
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 登陆账户
        /// </summary>
        public string Account { get; set; }
        /// <summary>
        /// 登陆密码
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string Secretkey { get; set; }
        /// <summary>
        /// 用户姓名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public string Gender { get; set; }
        /// <summary>
        /// 部门ID
        /// </summary>
        public string DepartmentId { get; set; }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string DepartmentName { get; set; }
        /// <summary>
        /// 默认角色主键
        /// </summary>
        public string RoleId { get; set; }
    }

    /// <summary>
    /// Session 帮助类
    /// </summary>
    public class RequestSession
    {
        public RequestSession()
        {
        }

        private static string _SESSION_USER = "SESSION_USER";
        public static void AddSessionUser(SessionUser user)
        {
            HttpContext rq = HttpContext.Current;
            rq.Session[_SESSION_USER] = user;
        }
        public static SessionUser GetSessionUser()
        {
            try
            {
                HttpContext rq = HttpContext.Current;
                return (SessionUser)rq.Session[_SESSION_USER];
            }
            catch (Exception)
            {
                throw new Exception(MessageHelper.MSG0031);
            }
        }
    }

}
